const ObsClient = require('esdk-obs-nodejs')
const ak = 'BCH9SADSMIKP9V07S1ZH'
const sk = 'aqDwdV1o48XDeZt9M8xOeXDcHhzBOJXbI9hAWbzH'
const obsClient = new ObsClient({
  access_key_id: ak,
  secret_access_key: sk,
  server: 'https://obs.cn-north-4.myhuaweicloud.com',
})
const host = 'https://leen-resource.obs.cn-north-4.myhuaweicloud.com'

module.exports = async (fastify, opts) => {
  fastify.get('/', async (request, reply) => {
    const { Policy: policy, Signature: signature } =
      obsClient.createPostSignatureSync({ Bucket: 'leen-resource' })
    reply.send({ host, AccessKeyId: ak, policy, signature })
  })
}
